package mybatis.hr.dao;

import mybatis.hr.domain.Employee;
import mybatis.hr.util.DatabaseManager;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.logging.log4j.core.net.Facility;

//싱글톤
public class EmployeeDAO {

	private static EmployeeDAO instance;
	private SqlSessionFactory factory;
	private EmployeeDAO() {
		DatabaseManager manager = DatabaseManager.getInstance();
		factory = manager.getSqlSessionFactory();
	}
	
	public static EmployeeDAO getInstance() {
		if(instance==null) {
			instance = new EmployeeDAO();
		}
		return instance;
	}
	
	public Employee selectEmployeeById(String employeeId) {
		SqlSession session = factory.openSession();
		try{
			return session.selectOne("hr.employee.selectEmployeeById", employeeId);
		}finally{
			session.close();
		}
	}
	
	
}
